#!/usr/bin/env python
# -*- encoding: utf-8 -*-
import datetime, os

import abc

from xpy3lib.utils import db_utils as util
from xpy3lib.LoggableObject import LoggableObject

class AbsDPJob(LoggableObject):
    __metaclass__ = abc.ABCMeta

    config = None
    db_conn_mpp = None
    db_conn_rds = None
    db_conn_dbprod7 = None

    max_end_time_cache = dict()
    query_sts_cache = dict()
    related_info_cache = dict()
    low_upper_limit_cache = dict()

    unit = None
    account = None
    cost_center = None
    account_period_start = None
    account_period_end = None

    def __init__(self, p_config=None,
                 p_db_conn_mpp=None,
                 p_db_conn_rds=None,
                 p_db_conn_dbprod7=None,
                 p_unit=None,
                 p_account=None,
                 p_cost_center=None,
                 p_account_period_start=None,
                 p_account_period_end=None):
        super(AbsDPJob, self).__init__()
        self.config = p_config

        self.db_conn_mpp = p_db_conn_mpp
        self.db_conn_rds = p_db_conn_rds
        self.db_conn_dbprod7 = p_db_conn_dbprod7

        self.unit = p_unit
        self.account = p_account
        self.cost_center = p_cost_center
        self.account_period_start = p_account_period_start
        self.account_period_end = p_account_period_end

        self.max_end_time_cache = dict()
        self.query_sts_cache = dict()
        self.related_info_cache = dict()
        self.low_upper_limit_cache = dict()

    def execute(self):
        self.logger.info('AbsDPJob.execute')
        start = datetime.datetime.now()

        self.do_execute()

        elapsed = float((datetime.datetime.now() - start).seconds)

        # NOTE clear cache 为下一次Job
        self.max_end_time_cache = dict()
        self.query_sts_cache = dict()
        self.related_info_cache = dict()
        self.low_upper_limit_cache = dict()
        pass

    @abc.abstractmethod
    def do_execute(self):
        self.logger.info('AbsDPJob.do_execute')
        pass